package cc.rengu.igas.channel.ncqs.core.model;

import cc.rengu.igas.channel.ncqs.core.model.request.*;
import org.springframework.util.StringUtils;

/**
 * 银联无卡快捷 on 2019/10/30.
 */
public enum NcqsTxnNumEnum {

    T00SH501("T00SH501", AgreePaySignWithSmsAcqRequest.class),
    T00SH502("T00SH502", ApplyPaySmsAcqRequest.class),
    T00SH503("T00SH503", AcctVerifyAcqRequest.class),
    T00SH504("T00SH504", DebitAcctSignWithSmsAcqRequest.class),
    T00SH505("T00SH505", AgreePaySignAcqRequest.class),
    T00SH506("T00SH506", DebitAcctSignAcqRequest.class),
    T00SH507("T00SH507", AgreePaySignRescindAcqRequest.class),
    T00SH508("T00SH508", TransStatQueryAcqRequest.class),
    T00SH509("T00SH509", DebitAcctSignRescindAcqRequest.class),
    P01SH501("P01SH501", AgreePayAcqRequest.class),
    P01SH502("P01SH502", DirectPayAcqRequest.class),
    P01SH503("P01SH503", DebitTransferAcqRequest.class),
    P01SH504("P01SH504", CreditPayAcqRequest.class),
    P04SH501("P04SH501", RefundAcqRequest.class),

    ;

    private String txnNum;

    private Class requestClazz;


    public String getTxnNum() {
        return txnNum;
    }

    public Class getRequestClazz() {
        return requestClazz;
    }

    NcqsTxnNumEnum(String txnNum, Class requestClazz) {
        this.txnNum = txnNum;
        this.requestClazz = requestClazz;
    }

    public static Class getRequestClassByTxnNum(String txnNum) {

        if (StringUtils.isEmpty(txnNum)) {
            return null;
        }

        for (NcqsTxnNumEnum txnNumEnum : values()) {
            if (txnNum.equals(txnNumEnum.getTxnNum())) {
                return txnNumEnum.getRequestClazz();
            }
        }

        return null;
    }

    public static boolean isSignRescindTxn(String txnNum) {

        if (StringUtils.isEmpty(txnNum)) {
            return false;
        }

        if (T00SH507.getTxnNum().equals(txnNum)
                || T00SH509.getTxnNum().equals(txnNum)) {
            return true;
        }

        return false;
    }

    public static boolean isSignTxn(String txnNum) {

        if (StringUtils.isEmpty(txnNum)) {
            return false;
        }

        if (T00SH505.getTxnNum().equals(txnNum)
                || T00SH506.getTxnNum().equals(txnNum)) {
            return true;
        }

        return false;
    }


    public static boolean isSmsTxn(String txnNum) {

        if (StringUtils.isEmpty(txnNum)) {
            return false;
        }

        if (T00SH501.getTxnNum().equals(txnNum)
                || T00SH502.getTxnNum().equals(txnNum)
                || T00SH504.getTxnNum().equals(txnNum)) {
            return true;
        }

        return false;
    }
}
